package net.entelijan.cobean.examples.showcase.filesel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JOptionPane;

import net.entelijan.cobean.core.ICobean;
import net.entelijan.cobean.filesel.DefaultFileselInitializer;
import net.entelijan.cobean.filesel.ExtensionsFileFilter;
import net.entelijan.cobean.filesel.FileSelectionMode;
import net.entelijan.scf.IShowcase;

public class FileselShowcase implements IShowcase<FileselPanel> {

	private ICobean<File> cobean1;
	private ICobean<File> cobean2;
	private ICobean<File> cobean3;

	public FileselShowcase() {
		super();
	}

	@Override
	public void init(final FileselPanel panel) {
		{
			// Create an initializer
			DefaultFileselInitializer ini = new DefaultFileselInitializer();
			ini.setId("cobean-showcase-01");
			ini.setFileSelectionMode(FileSelectionMode.DIRECTORIES_ONLY);
			ini.setMaxProposalSize(10);

			ini.setCoComboBox(panel.getDirComboBox());
			ini.setCoButton(panel.getDirSelButton());

			// Init and create the component bean. The bean is not yet used
			cobean1 = ini.initialize();
		}
		{
			// Create an initializer
			DefaultFileselInitializer ini = new DefaultFileselInitializer();
			ini.setId("cobean-showcase-02");
			ini.setFileSelectionMode(FileSelectionMode.FILES_ONLY);
			ini.setMaxProposalSize(10);

			ini.setCoComboBox(panel.getFileComboBox());
			ini.setCoButton(panel.getFileSelButton());

			// Init and create the component bean. The bean is not yet used
			cobean2 = ini.initialize();
		}
		{
			// Create an initializer
			DefaultFileselInitializer ini = new DefaultFileselInitializer();
			ini.setId("cobean-showcase-03");
			ini.setFileSelectionMode(FileSelectionMode.FILES_ONLY);
			ini.setMaxProposalSize(10);
			ini.setFileFilter(new ExtensionsFileFilter("txt",
					"Textfiles (*.txt)"));

			ini.setCoComboBox(panel.getTxtFileComboBox());
			ini.setCoButton(panel.getTxtFileSelButton());

			// Init and create the component bean. The bean is not yet used
			cobean3 = ini.initialize();
		}

		panel.getShowSelectionButton().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(panel, "" + cobean1.getValue()
						+ "\n" + cobean2.getValue() + "\n" + cobean3.getValue()
						+ "\n");
			}
		});

		panel.getSelectHomeButton().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				cobean1.setValue(new File(System.getProperty("user.home")));
			}

		});

	}

}
